package com.nuoniu.sibanyun.mapper.so;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.erp.ErpInvoiceType;
import com.nuoniu.sibanyun.entity.so.VSaleInvoiceMain;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 销售发票主表 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2020-12-07
 */
public interface VSaleInvoiceMainMapper extends BaseMapper<VSaleInvoiceMain> {

    @Select("select voucher_code from scs_invoice where date_format(create_date, #{dateStr})=date_format(now(), #{dateStr}) and company_id=#{companyId} order by create_date desc limit 1")
    String getCode(Integer companyId, String dateStr);

    @Select("select * from scs_invoice where source_voucher_id=#{id}")
    List<VSaleInvoiceMain> getBySourceId(Long id);

    @Select("select count(1) from scs_invoice where invoice_type_id in (${ids})")
    Integer getByInvoiceType(String ids);

    @Update("update scs_invoice set invoice_type_name=#{name} where invoice_type_id=#{id}")
    void updateInvoiceType(ErpInvoiceType invoiceType);

    @Select("select sum(amount) from scs_invoice_detail where order_id=#{id}")
    BigDecimal getAmount(Long id);
}
